import globalData from "@/plugins/data";

const FORM_AUTHORITY_PATH=`${_ctxPath}/common/content/common.js`;
const callbackObject={};
function formAuthority(){
  //参数准备
  let summaryIds=[globalData.summaryId];
  let affairIds=[globalData.affairId];
  let callBack=(flag)=>{
    window.callBackendMethod("colManager","updateAffairIdentifierForRelationAuth",{
      affairIds,
      flag
    });
  }
  if (!callbackObject.fn){
    let scriptElement = document.createElement('script');
    scriptElement.async=true;
    //动态引入表单授权的sdk
    scriptElement.src=FORM_AUTHORITY_PATH;
    scriptElement.onload=()=>{
      callbackObject.fn=window.setRelationAuth;
      callbackObject.fn(summaryIds,1,callBack);
    }
    document.body.appendChild(scriptElement);
    return;
  }
  callbackObject.fn(summaryIds,1,callBack);
}
export default function () {
  return new Promise((resolve) => {
    formAuthority.call(this);
    resolve();
  });
}